package cn.openea.perpartner.meily.web.controller;

import cn.openea.perpartner.common.core.web.controller.BaseController;
import cn.openea.perpartner.common.core.web.domain.AjaxResult;
import cn.openea.perpartner.meily.web.entity.GoodsSupplyChain;
import cn.openea.perpartner.meily.web.entity.vo.GoodsSupplyChainEditVo;
import cn.openea.perpartner.meily.web.service.IGoodsSupplyChainService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


/**
 * 商品供应链
 *
 * @author ysk
 * @email zane_ysk@qq.com
 * @date 2023-06-03 09:46:14
 */
@RestController
@RequestMapping("/goods/supply/chain")
public class GoodsSupplyChainController extends BaseController {

    @Resource
    private IGoodsSupplyChainService goodsSupplyChainService;

    @GetMapping("/list/{parentId}")
    public AjaxResult list(@PathVariable Long parentId) {
        List<GoodsSupplyChain> goodsSupplyChainList = goodsSupplyChainService.getListByParentId(parentId);
        return AjaxResult.success(goodsSupplyChainList);
    }

    @GetMapping("/info/{id}")
    public AjaxResult info(@PathVariable Long id) {
        GoodsSupplyChain goodsSupplyChain = goodsSupplyChainService.getById(id);
        return AjaxResult.success(goodsSupplyChain);
    }

    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody @Valid GoodsSupplyChainEditVo editVo) {
        goodsSupplyChainService.edit(editVo);
        return AjaxResult.success();
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody @Valid GoodsSupplyChainEditVo editVo) {
        goodsSupplyChainService.add(editVo);
        return AjaxResult.success();
    }
}
